/*****
 * abstract class by adding operator overloading.
 * 
 * ****/
#include <iostream>
using namespace std;
struct Boxer
{
    string name;
    int weight;
    unsigned short life;
    Boxer()
    {
        name = "unknown";
        weight = 0;
        life = 100;
    }
    Boxer(string pname, int pweight)
    {
        name = pname;
        weight = pweight;
        life = 100;
    }
    void introduce()
    {
        cout << "HI! I am " << name << " and I am " << weight << "kg!" << endl;
    }
    void show()
    {
        cout << name << ":" << life << "%" << endl;
    }
    unsigned short punch()
    {
        unsigned short t = rand() % 2;
        cout << name << " punch " << (t == 0 ? "left" : "right") << endl;
        return t;
    }
    void punch(Boxer &b)
    {
        unsigned short t = rand() % 2;
        cout << name << " punch " << (t == 0 ? "left" : "right") << endl;
        unsigned short t2 = b.dodge();
        if (t == t2)
            b.loseBlood();
        
    }
    unsigned short dodge()
    {
        unsigned short t = rand() % 2;
        cout << name << " dodge " << (t == 0 ? "left" : "right") << endl;
        return t;
    }
    void loseBlood()
    {
        life -= 10;
        if (life == 0)
            cout << name << " is dead!" << endl;
    }
    void operator-(unsigned short)
    {
        life-= 10;
    }
    bool ifLive()
    {
        return life > 0;
    }
};
  
    istream & operator >> (istream &in, Boxer &b)
    {
        in >> b.name >> b.weight;
        return in;
    }
    ostream & operator << (ostream &out, Boxer &b)
    {
        out <<"I am "<< b.name << " and I am " << b.weight<<"kg."<<endl;
        return out;
    }
int main()
{
    Boxer b1 = Boxer();
    cin>>b1;
    b1.introduce();
    Boxer b2("Ali", 80); // Boxer b2 = Boxer("Ali", 80);
    //b2.introduce();
    cout << b2;
    b1.show();
    b2.show();
    srand(time(NULL));
    cout << b1.name << " FIGHT! "<<b2.name << endl;
    while (b1.ifLive() && b2.ifLive())
    {
        cout<<string(5,'*')<<endl;
         if (b1.punch() == b2.dodge())
            b2 - 50;
        if (b2.punch() == b1.dodge())
            b1 -50;
        //b1.punch(b2);
        //b2.punch(b1);
        b1.show();
        b2.show();
    }
}